package com.bestcem.xm.om.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * bool状态枚举
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/27 15:14
 */
@AllArgsConstructor
@Getter
public enum BooleanStatusEnum {

    /**
     * bool状态枚举
     */
    YES(1, true, "是"),
    NO(0, false, "否");

    private Integer status;
    private Boolean boolValue;
    private String desc;

    /**
     * bool值转整形
     *
     * @param boolValue bool值
     * @return java.lang.Integer
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/05/27 15:25
     */
    public static Integer toInteger(Boolean boolValue) {
        return Stream.of(values()).filter(s -> s.getBoolValue().equals(boolValue))
                .map(BooleanStatusEnum::getStatus).findFirst().orElse(null);
    }

    /**
     * 整形转bool类型
     *
     * @param integerValue 整形值
     * @return java.lang.Boolean
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/05/27 15:26
     */
    public static Boolean toBoolean(Integer integerValue) {
        return Stream.of(values()).filter(s -> s.getStatus().equals(integerValue))
                .map(BooleanStatusEnum::getBoolValue).findFirst().orElse(null);
    }

}
